/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUIUtilities;

import SocialMatrixPackage.SocialMatrix;
import java.util.List;
import java.util.Random;
import java.util.Vector;
import javax.swing.JTree;
import multiarray.MultiArray;

/**
 *
 * @author Heather
 */
public class test
{

  /**
   * @param args the command line arguments
   */
  public static void main(String[] args)
  {
    // TODO code application logic here
    SocialMatrix sm = new SocialMatrix(new JTree());
    Vector<int[]> allCombos = sm.getAllCombinations();
    MultiArray pop = new MultiArray(sm.getDimensions());
    Random randGen = new Random();
    for (int[] i : allCombos)
    {
      pop.setElementAtIndex(i, randGen.nextInt(1000) + 10);
    //pop.setElementAtIndex(i, 700);
    }
    IntVectorComparator comparator = new IntVectorComparator(pop);

    Vector<List<int[]>> coalitions = new Vector<List<int[]>>();
    Vector<List<int[]>> sortedCoalitions = new Vector<List<int[]>>();
    int numberOfCoalitions = 5;
    System.out.println("num coal: " + numberOfCoalitions);
    for (int i = 0; i < numberOfCoalitions; i++)
    {
      Vector<int[]> coalition = new Vector<int[]>();
      int numberOfGroups = 15;
      for (int j = 0; j < numberOfGroups; j++)
      {
        int[] group = allCombos.get(randGen.nextInt(allCombos.size()));
        coalition.add(group);
      }

      Vector<int[]> postSortCoalition = ListUtilities.sortByPop(coalition, comparator);
      if (i == 0)
      {        
        printCoalition(coalition, pop);
        System.out.println("***");
        printCoalition(postSortCoalition, pop);
      }

      coalitions.add(coalition);
      sortedCoalitions.add(postSortCoalition);
    }

    System.out.println(CoalitionUtilities.getPartitionString(coalitions));
    System.out.println(CoalitionUtilities.getPartitionString(sortedCoalitions));
    System.out.println("are coalitions same?: " + ListUtilities.doPartitionsHaveSameElements(coalitions, sortedCoalitions));

  }

  public static void printAllPops(Vector<int[]> input, MultiArray pop)
  {
    for (int[] i : input)
    {
      System.out.println(pop.getElementAtIndex(i));
    }
  }

  public static void printCoalition(Vector<int[]> input, MultiArray pop)
  {
    String printS = "";

    for (int[] i : input)
    {
      int iL = i.length;

      printS += "{";
      for (int j = 0; j < iL - 1; j++)
      {
        printS += i[j] + ", ";
      }

      printS += i[iL - 1] + "}";
      printS += ": " + pop.getElementAtIndex(i) + "\n";
    }

    System.out.println(printS);
  }
}
